//
// Description: 233. 数字 1 的个数
// Created by Loading on 2021/8/13.
//

#include <bits/stdc++.h>

using namespace std;

int countDigitOne(int n) {
    int cnt = 0;
    // 按每一位的 1 的个数分别计算，累加
    for (int i = 1; i <= 10; ++i) {
        long long base = pow(10, i);
        // high low current 分别表示当前位的高置位、低置位、当前位，例如：3201，current = 0 时，high = 32，low = 1
        int high = n / base;
        int low = (n % base) % (base / 10);
        int current = (n % base) / (base / 10);
        // 按照当前位数字，分三种情况讨论
        if (current == 0) {
            cnt += high * base / 10;
        } else if (current == 1) {
            cnt += high * base / 10 + (low + 1);
        } else {
            cnt += (high + 1) * base / 10;
        }
    }

    return cnt;
}

int main() {
    int n = 1000000000;
    int res = countDigitOne(n);
    cout << res << endl;
}